package com.itheima.reggie.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.reggie.domain.Category;
import com.itheima.reggie.domain.Setmeal;
import com.itheima.reggie.dto.SetmealDto;
import com.itheima.reggie.mapper.CategoryMapper;
import com.itheima.reggie.mapper.SetmealMapper;
import com.itheima.reggie.service.CategoryService;
import com.itheima.reggie.service.SetmealService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class SetmealServiceImpl extends ServiceImpl<SetmealMapper, Setmeal> implements SetmealService {

//    private CategoryService categoryService;
//
//    @Override
//    public List<SetmealDto> selectByPage(int page, int pageSize, String name) {
//        Page<Setmeal> setmealPage=new Page<>(page,pageSize);
//        LambdaQueryWrapper<Setmeal> queryWrapper=new LambdaQueryWrapper();
//        queryWrapper.like(name!=null,Setmeal::getName,name);
//        //设置排序构造器
//        queryWrapper.orderByAsc(Setmeal::getUpdateTime);
//        this.page(setmealPage, queryWrapper);
//
//        List<Setmeal> records = setmealPage.getRecords();
//        List<SetmealDto> list;
//        list=records.stream().map((item)->{
//            Long categoryId = item.getCategoryId();
//            LambdaQueryWrapper<Category> queryWrapper1=new LambdaQueryWrapper<>();
//            queryWrapper1.eq(Category::getId,categoryId);
//            Category category = categoryService.getOne(queryWrapper1);
//            //创建一个setmealDto对象
//            SetmealDto setmealDto = new SetmealDto();
//            //将setmeal拷贝到setmealDto对象上
//            BeanUtils.copyProperties(item,setmealDto);
//            //给setmealDto对象设置套餐名
//            setmealDto.setCategoryName(category.getName());
//            return setmealDto;
//        }).collect(Collectors.toList());
//
//
//    }
}
